package com.lixia.lxframework.framework.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @Author Mr.wang
 * @Description
 * @Date 2020/3/25
 */
@Aspect
public class LogAspect {

    private static final Logger LOGGER = LoggerFactory.getLogger(LogAspect.class);

    /**
     * Controller层切点
     */
    @Pointcut("@annotation(com.lixia.lxframework.framework.aspect.annotation.Log)")
    public void timeLinePointCut() {
    }

    /**
     * 环绕通知
     *
     * @param joinPoint 切点
     * @return
     * @throws Throwable
     */
    @Around("timeLinePointCut()")
    public Object aroundMethod(ProceedingJoinPoint joinPoint) {
        Object[] args = joinPoint.getArgs();
        Object proceed = null;
        try {
            proceed = joinPoint.proceed(args);
        } catch (Throwable throwable) {
            LOGGER.error(throwable.getCause().getMessage());
        }
        return proceed;
    }
}
